<?php

namespace app\common\logic;

use app\common\model\systemAuth;

class systemAuthLogic extends commonLogic
{
	public function getAuthList($id, $type = 0)
	{ //id=0 全部权限 type = 0 导航 type = 1 列表
		$list = systemAuth::all(function ($query) use ($type) {
			$map = [];
			if ($type == 0) {
				$map['status'] = 1;
			}
			$query->field('id,pid,alias,name,status,sort,icon,level');
			$query->where($map);
			$query->order('sort asc');
		})->toArray();
		$lists = getTreeList($list);
		foreach ($lists as $k => $v) {
			$lists[$k]['defaulturl'] = '';
			if (!empty($v['children']) && count($v['children']) > 0) {
				foreach ($v['children'] as $kk => $vv) {
					if (!empty($vv['children']) && count($vv['children']) > 0) {
						$lists[$k]['defaulturl'] = $v['children'][0]['children'][0]['alias'];
					} else {
						if ($type == 0) {
							unset($lists[$k]['children'][$kk]);
						}
					}
				}
			} else {
				if ($type == 0) {
					unset($lists[$k]);
				}
			}
		}
		return array_values($lists);
	}
}
